#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/gpio.h>

#include "button.h"

/*定义系统调用接口*/
static void button_release(struct device *dev)
{
	printk("<kernel>call function:%s\n",__FUNCTION__);
}


/*全局变量*/
//定义1个button引脚
struct rk3399_button_gpio button_gpios[] = 
{
	[0] = {
		.gpio = 5,
		.desc = "gpio_button",
	}, 
};

//定义平台数据对象
struct button_platform_data rk_button_platform_data = 
{
	.pbutton_gpio = button_gpios,
	.nbuttons = ARRAY_SIZE(button_gpios),
};

//定义资源对象
static struct resource button_resources[] = 
{
	[0] = {
		.start	= CRU_CLKGATE_CON31,
		.end	= CRU_CLKGATE_CON31 + SIZE_4 - 1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start = 75,
		.end = 75,
		.flags = IORESOURCE_IRQ,
	},	
	[2] = {
		.start = GRF_GPIO2A_IOMUX,
		.end = GRF_GPIO2A_IOMUX + SIZE_4 - 1,
		.flags = IORESOURCE_MEM,
	},
	[3] = {
		.start	= GPIO2_SWPORTA_DDR,
		.end	= GPIO2_SWPORTA_DDR + SIZE_4 - 1,
		.flags	= IORESOURCE_MEM,
	},
	[4] = {
		.start = GPIO2_SWPORTA_DR,
		.end = GPIO2_SWPORTA_DR + SIZE_4 - 1,
		.flags = IORESOURCE_MEM,
	},
	
};

//定义平台设备对象		
static struct platform_device button_device = 
{
	.name						= "rk3399_button",
	.id							= -1,
	.dev 						= 
		{
			.release = button_release,
			.platform_data = &rk_button_platform_data,
		},
	.resource				= button_resources,
	.num_resources	= ARRAY_SIZE(button_resources),
};



/*入口函数*/
static int __init device_mod_init(void)
{
	printk("<kernel>call function:%s\n",__FUNCTION__);	
	return platform_device_register(&button_device);
}

/*出口函数*/
static void __exit device_mod_exit(void)
{
	printk("<kernel>call function:%s\n",__FUNCTION__);
	platform_device_unregister(&button_device);
}

module_init(device_mod_init);
module_exit(device_mod_exit);
MODULE_LICENSE("GPL");


